home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Graphics / SPD / Sources / def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-27  |  5.6 KB  |  223 lines  |  [TEXT/R*ch]

  1. /*
  2.  * def.h contains some useful definitions for "C" programs.
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  *
  6.  * Modified: 1 October 1992
  7.  *           Alexander R. Enzmann
  8.  * Modified: 14 December 1992  - Better Mac (MPW) compatibility
  9.  *           Eduard [esp] Schwan
  10.  * Modified: 2 August 1993  - More ANSI C & Mac compatibility fixes
  11.  *           Eduard [esp] Schwan
  12.  * Modified: 4 September 1993  - Added one more generator (LATTICE)
  13.  *           Antonio [acc] Costa
  14.  * Modified: 6 September 1993  - Changed LATTICE to GENERIC, other renames
  15.  *           Eric Haines
  16.  * Modified: 16 September 1993  - Added SPD_LATTICE & SPD_SHELLS defines
  17.  *           Eduard [esp] Schwan
  18.  * Modified: 27 July 1994  - Added __MWERKS__ define for Metrowerks compiler
  19.  *           Eduard [esp] Schwan
  20.  *
  21.  */
  22.  
  23. #ifndef DEF_H
  24. #define DEF_H
  25.  
  26. #if __cplusplus
  27. extern "C" {
  28. #endif
  29.  
  30. /*
  31.  * Each data base/program is defined here.  These are used as
  32.  * parameters to the PLATFORM_INIT() macro, in case the programs
  33.  * need to behave differently based on the type of db run.  For
  34.  * example, the Macintosh version must prompt the user for input
  35.  * parameters instead of getting them on the command line.  This
  36.  * allows the Mac to use a different dialog box for each program.
  37.  */
  38. #define SPD_MIN            1
  39. #define SPD_BALLS        1
  40. #define SPD_GEARS        2
  41. #define SPD_MOUNT        3
  42. #define SPD_RINGS        4
  43. #define SPD_TEAPOT        5
  44. #define SPD_TETRA        6
  45. #define SPD_TREE        7
  46. #define SPD_READDXF        8
  47. #define SPD_LATTICE        9
  48. #define SPD_SHELLS        10
  49. #define SPD_READNFF        11
  50. #define SPD_READOBJ        12
  51. #define SPD_GENERIC        13
  52. #define SPD_MAX            SPD_GENERIC
  53.  
  54.  
  55. /* ---- Macintosh-specific definitions here ---- */
  56.  
  57. #if defined(applec) || defined(THINK_C) || defined(__MWERKS__)
  58. #define PARAMS(x)  x
  59.  
  60. /* If OUTPUT_TO_FILE is defined, output goes to new text file, not to stdout */
  61. #define OUTPUT_TO_FILE            true
  62. #define PLATFORM_INIT(spdType)    MacInit(&argc, &argv, spdType)
  63. #define PLATFORM_MULTITASK()    MacMultiTask()
  64. #define PLATFORM_SHUTDOWN()        MacShutDown()
  65.  
  66. #define EPSILON  1.0e-15
  67. #define EPSILON2 1.0e-7
  68.  
  69.  
  70. #if defined(applec)
  71. #include <sane.h>
  72. #define PI    pi()
  73. #endif /* applec */
  74.  
  75.  
  76. /*
  77.  * declared in MAC.C
  78.  */
  79. extern void        MacInit(int *argcp, char ***argvp, int spdType);
  80. extern void        MacMultiTask(void);
  81. extern void        MacShutDown(void);
  82. /* extern short    macParmOutFormat; */
  83. /* extern short    macParmSize; */
  84. /* extern short    macParm2; */
  85. #endif /* applec || THINK_C */
  86.  
  87.  
  88.  
  89. /* Use "PARAMS(x) ()" above if your compiler can't handle function prototyping,
  90.  * "PARAMS(x) x" if it can use ANSI headers.
  91.  */
  92. #ifndef PARAMS
  93.  
  94. /* check if ANSI headers should be available */
  95. #if __STDC__ || defined(__cplusplus)
  96. /* yes, ANSI headers */
  97. #define PARAMS(x)  x
  98. #else
  99. /* no, no ANSI headers */
  100. #define PARAMS(x) ()
  101. #endif
  102.  
  103. #endif
  104.  
  105.  
  106. /*
  107.  * PLATFORM_xxx macros are used to allow different OS platforms
  108.  * hooks to do their own initialization, periodic tasks, and
  109.  * shutdown cleanup, if needed. [esp]
  110.  */
  111.  
  112. #ifndef PLATFORM_INIT
  113. #define PLATFORM_INIT(spdType)
  114. #endif /* PLATFORM_INIT */
  115.  
  116. #ifndef PLATFORM_MULTITASK
  117. #define PLATFORM_MULTITASK()
  118. #endif /* PLATFORM_MULTITASK */
  119.  
  120. #ifndef PLATFORM_SHUTDOWN
  121. #define PLATFORM_SHUTDOWN()
  122. #endif /* PLATFORM_SHUTDOWN */
  123.  
  124.  
  125. /* exit codes - define as you wish */
  126. #define    EXIT_SUCCESS    0
  127. #define    EXIT_FAIL    1
  128.  
  129. #ifndef EPSILON
  130. #define EPSILON 1.0e-8
  131. #endif
  132.  
  133. #ifndef EPSILON2
  134. #define EPSILON2 1.0e-6
  135. #endif
  136.  
  137. #ifndef FALSE
  138. #define FALSE 0
  139. #endif
  140.  
  141. #ifndef NULL
  142. #define NULL 0
  143. #endif
  144.  
  145. #ifndef TRUE
  146. #define TRUE 1
  147. #endif
  148.  
  149. #ifndef PI
  150. #define PI 3.141592653589793
  151. #endif
  152.  
  153. typedef double MATRIX[4][4] ;  /* row major form */
  154.  
  155. typedef    double    COORD3[3] ;
  156. typedef    double    COORD4[4] ;
  157.  
  158. /* COORD3/COORD4 indeces */
  159. #define    X    0
  160. #define    Y    1
  161. #define    Z    2
  162. #define    W    3
  163.  
  164. /* COORD3 (color) indeces */
  165. #define    R_COLOR    0
  166. #define    G_COLOR    1
  167. #define    B_COLOR    2
  168.  
  169. #define POW(A,B)     ( (A) == 0.0 ? 0.0 : ( (B) == 0.0 ? 1.0 : pow(A, B) ) )
  170. #define SGN(A)       ( (A) < 0.0 ? -1.0 : ( (A) > 0.0 ? 1.0 : 0.0) )
  171. #define ABSOLUTE(A)        ( (A) < 0 ? -(A) : (A) )
  172. #define    FRACTION(A)        ( (A) - (int)(A) )
  173. #define    IS_VAL_ALMOST_ZERO(A,E)    ( ABSOLUTE(A) <= (E) )
  174. #define    MAX(A,B)        ( (A) > (B) ? (A) : (B) )
  175. #define    MIN(A,B)        ( (A) < (B) ? (A) : (B) )
  176. #define SQR(A)            ( (A) * (A) )
  177.  
  178. #define ADD2_COORD3(r,a)    { (r)[X] += (a)[X]; (r)[Y] += (a)[Y];\
  179.                   (r)[Z] += (a)[Z]; }
  180. #define ADD3_COORD3(r,a,b)    { (r)[X] = (a)[X] + (b)[X];\
  181.                   (r)[Y] = (a)[Y] + (b)[Y];\
  182.                   (r)[Z] = (a)[Z] + (b)[Z]; }
  183. #define COPY_COORD3(r,a)    { (r)[X] = (a)[X];\
  184.                   (r)[Y] = (a)[Y];\
  185.                   (r)[Z] = (a)[Z];}
  186. #define COPY_COORD4(r,a)    { (r)[X] = (a)[X];\
  187.                   (r)[Y] = (a)[Y];\
  188.                   (r)[Z] = (a)[Z];\
  189.                   (r)[W] = (a)[W]; }
  190. #define CROSS(r,a,b)        { (r)[X] = (a)[Y] * (b)[Z] - (a)[Z] * (b)[Y];\
  191.                   (r)[Y] = (a)[Z] * (b)[X] - (a)[X] * (b)[Z];\
  192.                   (r)[Z] = (a)[X] * (b)[Y] - (a)[Y] * (b)[X]; }
  193. #define DOT_PRODUCT(a,b)    ( (a)[X] * (b)[X] +\
  194.                   (a)[Y] * (b)[Y] +\
  195.                   (a)[Z] * (b)[Z] )
  196. #define DOT4(a,b)        ( (a)[X] * (b)[X] +\
  197.                   (a)[Y] * (b)[Y] +\
  198.                   (a)[Z] * (b)[Z] +\
  199.                   (a)[W] * (b)[W] )
  200. #define IS_COORD3_ALMOST_ZERO(a,E)    (\
  201.                      IS_VAL_ALMOST_ZERO( (a)[X], (E) )\
  202.                   && IS_VAL_ALMOST_ZERO( (a)[Y], (E) )\
  203.                   && IS_VAL_ALMOST_ZERO( (a)[Z], (E) ) )
  204. #define SET_COORD3(r,A,B,C)    { (r)[X] = (A); (r)[Y] = (B); (r)[Z] = (C); }
  205. #define SET_COORD4(r,A,B,C,D)    { (r)[X] = (A); (r)[Y] = (B); (r)[Z] = (C);\
  206.                   (r)[W] = (D); }
  207. #define SUB2_COORD3(r,a)    { (r)[X] -= (a)[X]; (r)[Y] -= (a)[Y];\
  208.                   (r)[Z] -= (a)[Z]; }
  209. #define SUB3_COORD3(r,a,b)    { (r)[X] = (a)[X] - (b)[X];\
  210.                   (r)[Y] = (a)[Y] - (b)[Y];\
  211.                   (r)[Z] = (a)[Z] - (b)[Z]; }
  212. #define LERP_COORD(r, a, b, u) { (r)[X] = (a)[X] + (u) * ((b)[X] - (a)[X]);\
  213.                  (r)[Y] = (a)[Y] + (u) * ((b)[Y] - (a)[Y]);\
  214.                  (r)[Z] = (a)[Z] + (u) * ((b)[Z] - (a)[Z]); }
  215.  
  216.  
  217. #if __cplusplus
  218. }
  219. #endif
  220.  
  221.  
  222. #endif /* DEF_H */
  223.